package logic

import (
	"context"
	"rent-ease/models/mysql"

	"rent-ease/rentrpc/internal/svc"
	"rent-ease/rentrpc/rentrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type HouseShowLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewHouseShowLogic(ctx context.Context, svcCtx *svc.ServiceContext) *HouseShowLogic {
	return &HouseShowLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 房源详情
func (l *HouseShowLogic) HouseShow(in *rentrpc.HouseShowRequest) (*rentrpc.HouseShowResponse, error) {
	// todo: add your logic here and delete this line

	var house mysql.House

	err := house.FindHouseById(mysql.DB, in.HouseId)
	if err != nil {
		return nil, err
	}

	return &rentrpc.HouseShowResponse{
		HouseId: int64(house.ID),
		Title:   house.Title,
		Desc:    house.Desc,
		Price:   float32(house.Price),
	}, nil
}
